package com.geline.easytrans.enums;

import lombok.Getter;

import java.util.function.Function;

/**
 * 定制脱敏策略
 * @author: mengxin
 * @date: 2023/4/13 10:52
 */
@Getter
public enum SensitiveStrategy {
    //USERNAME("用户名", s -> s.replaceAll("(\\S)\\S(\\S*)", "$1*$2")),
    //EMAIL("Email", s -> s.replaceAll("(\\S{3})\\S{8}(\\S{4})", "$1****$2")),
    //CODE("编码", s -> s.replaceAll("(\\S{3})\\S{8}(\\S{3})", "$1****$2")),
    //BANK_CARD("银行卡", s -> s.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2")),
    //ID_CARD("身份证", s -> s.replaceAll("(\\d{4})\\d{10}(\\w{4})", "$1****$2")),
    //PHONE("手机号", s -> s.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2")),
    //PASSWORD("密码", s -> s.replaceAll("(\\S{3})\\S*(\\S{2})", "$1****$2")),
    //ADDRESS("地址", s -> s.replaceAll("(\\S{2})\\S{2}(\\S*)\\S{2}", "$1****$2****")),
    AUTO("根据长度自动切换策略", s -> s),
    SHORT("小于等于5", s -> s.replaceAll("(\\S)\\S(\\S*)", "$1*$2")),
    MIDDLE("小于等于20", s -> s.replaceAll("(\\S{3})\\S*(\\S{2})", "$1****$2")),
    LONG("大于20", s -> s.replaceAll("(\\S{2})\\S{2}(\\S*)\\S{2}", "$1****$2****")),
    FULL("全密文", s -> s.replaceAll("(\\S*)", "****"));

    private String desc;
    private final Function<String, String> desensitizer;

    SensitiveStrategy(String desc, Function<String, String> desensitizer) {
        this.desc = desc;
        this.desensitizer = desensitizer;
    }

    public Function<String, String> desensitizer() {
        return desensitizer;
    }
}
